lscolors
A cross-platform library for colorizing paths according to the LS_COLORS
environment variable (like ls
).
Usage
use ;
let lscolors = from_env.unwrap_or_default;
let path = "some/folder/test.tar.gz";
let style = lscolors.style_for_path;
// If you want to use `ansi_term`:
let ansi_style = style.map
.unwrap_or_default;
println!;
// If you want to use `nu-ansi-term` (fork of ansi_term) or `gnu_legacy`:
let nu_ansi_style = style.map
.unwrap_or_default;
println!;
// If you want to use `crossterm`:
let crossterm_style = style.map
.unwrap_or_default;
println!;
Command-line application
This crate also comes with a small command-line program lscolors
that
can be used to colorize the output of other commands:
> find |
> rg |
You can install it by running cargo install lscolors
or by downloading one
of the prebuilt binaries from the release page.
If you want to build the application from source, you can run
cargo build --release --features=nu-ansi-term --locked
Features
// Cargo.toml
// use ansi-term coloring
lscolors =
// use crossterm coloring
lscolors =
// use nu-ansi-term coloring
lscolors =
// use nu-ansi-term coloring in gnu legacy mode with double digit styles
lscolors =
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
References
Information about the LS_COLORS
environment variable is sparse. Here is a short list of useful references:
LS_COLORS
implementation in the GNU coreutils version ofls
(the reference implementation)LS_COLORS
implementation inbfs
by @tavianator- The
DIR_COLORS(5)
man page